import  random
import csv
from datetime import datetime

def read_test_cases(filename):
    with open(filename,"r") as f:
        reader = csv.reader(f)
        return [row for row in reader]

def generate_html_report(results):
    html = "<h1>测试报告 - {}</h1><ul>".format(datetime.now())
    for case,result in results:
        color = "green" if result == "PASS" else "red"
        html += f"<li style='color:{color}'>{case}:{result}</li>"
    html += "<.ul>"
    with open("../report.html", "w") as f:
        f.write(html)

test_cases = read_test_cases("../test_cases.csv")
results = []
for case in test_cases:
    actual = "PASS" if random.random() > 0.2 else "FAIL"
    results.append((case,actual))
generate_html_report(results)
print("testting finished!")